
import { Route } from '@/api';

// 加载
const load_list = async (context, payload) => {
    let { status, data } = await Route.all(payload);
    if (status) {
        context.commit("UPDATE_ROUTE", data);
    }
}

const insert_route = async (context, payload) => {
    let { status, msg, data } = await Route.add(payload);
    if (status) {
        context.commit("INSERT_ROUTE", { ...data, ...payload })
    }
    return { status, msg, data }
}

// 修改
const edit_route = async (context, payload) => {
    let { route_id } = payload;
    let { status, msg } = await Route.edit(route_id, payload);
    return { status, msg }
}

const remove_route = async (context, payload) => {
    let { route_id, permission_id } = payload.route;
    let { status, msg, data } = await Route.remove(route_id, { permission_id });
    if (status) {
        context.commit("REMOVE_ROUTE", route_id);
    }
    return { status, msg, data }
}

export default {
    load_list,
    insert_route,
    edit_route,
    remove_route
}